package com.jt.controller;
import com.jt.service.FileService;
import com.jt.vo.ImageVo;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author Yu
 * @create 2025/07/08
 * @description
 */
@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public SysResult upload(MultipartFile file) throws IOException {
        ImageVo imageVo = fileService.upload(file);
        if (imageVo == null){
            return SysResult.fail();
        }
        return SysResult.success(imageVo);
    }

    @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){
        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }
}

